<?php
	require '../Class/autoload.php';
	date_default_timezone_set("Asia/Chongqing");
	session_start();








	//===== 生成验证码
	if($_REQUEST['type'] == 'code'){
		require_once "../Class/Plugin/VCode.class.php";
		if(CheckOrigin()){
			Code\VCode::GetCode();
		}
		exit;
	}





	//===== ### 请求token

	if($_REQUEST['type'] == 'token'){
		echo $token = md5(time()).md5(rand());
		$_SESSION[$_REQUEST['token_name']]= $token;
		exit;
	}





	//===== ### 验证token

	$token_arr = array(		// 跳过token验证的type项 添加到这里

	);
	if(!in_array($_REQUEST['type'],$token_arr)){
		if(!@$_REQUEST['remote_token']){	//验证本地token
			if(!@$_REQUEST['token'] || $_REQUEST['token'] != $_SESSION[$_REQUEST['type']]){
				$_REQUEST['token'] = md5(rand());
				exit('10001');
			}
			$_REQUEST['token'] = md5(rand());
		}else{		//验证远程token
			if(!CheckRemoteToken($_REQUEST['remote_token'])){
				exit('10002');	//远程token 验证失败
			}
		}
	}




	switch ($_REQUEST['type']) {

		//修改砍价商品状态
		case 'ChangeFreeGoodsStat':
			$id = intval($_POST['id']);
			$stat = intval($_POST['stat']);
			if(!$id || !$stat){
				return;
			}

			$pdo = MyPdoCounty::init();
			$sql = "update shop_free set free_stat = ? where id = ?";
			echo $pdo->dml($sql,array($stat,$id));
			break;


		//获取砍价商品列表
		case 'GetFreeGoodsList':
			$pnow = intval($_POST['pnow'])?:1;
			$search = ChangeChar(I('search','post'));
			$get_type = ChangeChar(I('get_type','post'));
			$psize = 10;
			$limit_start = ($pnow - 1) * $psize; 
			$fields = 'id,store_id,title,price,banner,free_stat,ctime';

			$sql = "select id,store_id,title,price,banner,free_stat,ctime from shop_free limit {$limit_start},{$psize}";
			$arr = array();

			if($get_type == 'all'){
				if($search){
					$sql = "select {$fields} from shop_free use index(c) where title = ? limit 100 union select {$fields} from shop_free use index(c) where title like ? limit 100 union select {$fields} from shop_free use index(PRI) where title like ? and id < 200000 limit {$limit_start},{$psize}";
					$arr = array($search,"{$search}%","%{$search}%");
				}else{
					$sql = "select id,store_id,title,price,banner,free_stat,ctime from shop_free limit {$limit_start},{$psize}";
				}
			}else{
				if($search){
					$sql = "select {$fields} from shop_free use index(c) where title = ? and free_stat = ? limit 100 union select {$fields} from shop_free use index(c) where title like ? and free_stat = ? limit 100 union select {$fields} from shop_free use index(PRI) where title like ? and id < 200000 and free_stat = ? limit {$limit_start},{$psize}";
					$arr = array($search,$get_type,"{$search}%",$get_type,"%{$search}%",$get_type);
				}else{
					$sql = "select id,store_id,title,price,banner,free_stat,ctime from shop_free where free_stat = ? limit {$limit_start},{$psize}";
					$arr = array($get_type);
				}
			}



			$pdo = MyPdoCounty::init();
			$res = $pdo->dql($sql,$arr);
			echo json_encode($res);
			break;



		//删除域名 (多选) 
		case 'ServerDomainDelMulti':
			$ids=I('ids','post');
			$ids2 = explode(',',$ids);
			$id_str = '';
			foreach($ids2 as $v){
				$id_arr[] = $v;
				$id_str .= '?'.',';
			}
			$id_str = trim($id_str,',');
			$pdo = MyPdoShare::Init();
			$sql = 'delete from share_domain where id in('.$id_str.')';
			$res = $pdo->dml($sql,$id_arr);
			if($res){
				$save_stat_path = '../Cache/Domain/domain_stat';
				$status_name = 'domain_list';
				DomainUpdateStat($config,$save_stat_path,$status_name);
				exit('ok');
			}else{
				exit('err');
			}
			break;

		//删除域名 
		case 'ServerDomainDel':
			$id=intval(I('id','post'));
			$pdo = MyPdoShare::Init();
			$sql = 'delete from share_domain where id = ?';
			$res = $pdo->dml($sql,array($id));
			if($res){
				$save_stat_path = '../Cache/Domain/domain_stat';
				$status_name = 'domain_list';
				DomainUpdateStat($config,$save_stat_path,$status_name);
				exit('ok');
			}else{
				exit('err');
			}
			break;


		//添加域名
		case 'ServerDomainAdd':
			$url = I('url','post');
			$info = I('info','post');
			
			$pdo = MyPdoShare::Init();
			$sql = 'insert ignore into share_domain(domain,info) values(?,?)';
			$res = $pdo->dml($sql,array($url,$info));
			if($res){
				$save_stat_path = '../Cache/Domain/domain_stat';
				$status_name = 'domain_list';
				DomainUpdateStat($config,$save_stat_path,$status_name);
				exit('ok');
			}else{
				exit('err');
			}
			break;




		//获取域名列表
		case 'GetServerDomainList':
			$pdo = MyPdoShare::Init();
			$sql = 'select * from share_domain order by id desc';
			$res = $pdo->dql($sql,array());
			if($res){
				foreach($res as $v){
					$data[] = $v['domain'];
				}
				//$res2 = 'Gets('.json_encode($data).')';
				$res2 = json_encode($data);
			}else{
				$res2 = '[]';
			}
			$path = '/DomainList/domain_list.html';
			$stat_path = '../Cache/Domain/domain_stat';
			if(file_exists($stat_path)){
				UpyunAddFile($config,$path,$res2);
				//S('../zshare/DomainList/domains.html',$res2);
				unlink($stat_path);
			}
			exit(json_encode($res));
			break;




		//获取商品详情
		case 'GetGoodsDetail':
			$id = intval(I('id','post'));
			$fields = 'id,store_id,type_set,title,price,info,number,banner,ctime,goods_stat';
			$pdo = MyPdoCounty::init();
			$sql = "select {$fields} from shop_goods where id = ?";
			$res = $pdo->dql($sql,array($id),1);
			if($res){
				echo json_encode($res);
			}else{
				echo 'err';
			}
			break;


		//获取商品详情中的图片列表
		case 'GetGoodsDetailImgs':
			$id = intval(I('id','post'));
			$pdo = MyPdoCounty::init();
			$sql = 'select addr from shop_img where gid = ?';
			$res = $pdo->dql($sql,array($id));
			if($res){
				echo json_encode($res);
			}else{
				echo 'err';
			}
			break;



		//审核商品修改状态
		case 'ChangeGoodsStat':
			$id = intval(I('id','post'));
			$stat = intval(I('stat','post'));
			if(!$id || !$stat){
				exit('err1');
			}
			//$stat = ($stat+1)>4?1:$stat+1;
			$pdo = MyPdoCounty::init();
			$sql = 'update shop_goods set goods_stat=?,utag1=utag1+1 where id=?';
			$res = $pdo->dml($sql,array($stat,$id));
			if($res){
				if($stat == 2){ //通过了需要更新upyun缓存
					$fields = 'g.id,g.store_id,g.title,g.price,g.info,g.number,g.banner,g.utag1,g.utag2,g.utag3,s.utag1 as s_utag1';
					$sql = "select {$fields} from shop_goods as g join shop_store as s on g.store_id = s.id where g.goods_stat = 2 and g.id = ?";
					$res = $pdo->dql($sql,array($id),1);
					if($res){
						$res_tmp = array(
							$res['id'],
							$res['store_id'],
							$res['banner'],
							ChangeChar($res['title'],1),
							$res['price'],
							ChangeChar($res['info'],1),
							$res['number'],
							$res['utag1'],
							$res['utag3'],
							$res['s_utag1']
						);
						$res2 = json_encode($res_tmp);
						$cache_name = '/detail_goods/dg_'.$_SESSION['CountyInfo'][0].'_'.$id;
						$cache_path = $cache_name.'.html';
						$cache_tag_path = $cache_name.'_utag1.html';
						UpyunAddFile($config,$cache_path,$res2);
						UpyunAddFile($config,$cache_tag_path,$res['utag1']);
					}

				}
				$sql3 = 'update shop_store set utag3=utag3+1 where id = (select store_id from shop_goods where id = ?)';
				$res3 = $pdo->dml($sql3,array($id));
				exit('ok');
			}else{
				exit('err2');
			}

			break;



		//获取商品列表
		case 'GetGoodsList':
			$store_id = intval(I('store_id','post'));
			$psize = intval(I('psize','post'));
			$psize = $psize > 0?$psize:5;
			$pnow = intval(I('pnow','post'));
			$pnow = $pnow > 0?$pnow:1;
			$search = ChangeChar(I('search','post'));
			$limit_start = ($pnow-1) * $psize;

			$fields = 'id,store_id,title,price,goods_stat';
			
			$type_sel = intval(I('type_sel','post'));
			
			$pdo = MyPdoCounty::init();
			if($store_id > 0){ 	//商户获取商品列表
				if($type_sel && $type_sel != 7){   //按分类
					if($search){
						$sql = "select {$fields} from shop_goods where store_id = ? and goods_stat = ? and title like ? order by id desc limit {$limit_start},{$psize}";
						$arr = array($store_id,$type_sel,'%'.$search.'%');
					}else{
						$sql = "select {$fields} from shop_goods where store_id = ? and goods_stat = ? order by id desc limit {$limit_start},{$psize}";
						$arr = array($store_id,$type_sel);
					}
				}else{                            //全部
					if($search){
						$desc = GetDescId($pdo,'shop_goods',50000); 	//获取倒数第n个id值
						$sql = "select {$fields} from shop_goods where store_id = ? and goods_stat != 6 and title like ? order by id desc limit {$limit_start},{$psize}";
						$arr = array($store_id,'%'.$search.'%');
					}else{
						$sql = "select {$fields} from shop_goods where store_id=  ? and goods_stat != 6 order by id desc limit {$limit_start},{$psize}";
						$arr = array($store_id);
					}
				}
			}else{  //非商户获取列表
				if($type_sel && $type_sel != 7){   //按分类
					if($search){
						$desc = GetDescId($pdo,'shop_goods',50000); 	//获取倒数第n个id值
						$sql = "select {$fields} from shop_goods where goods_stat = {$type_sel} and title =? limit 1000 union select {$fields} from shop_goods where goods_stat = {$type_sel} and title like ? limit 1000 union select {$fields} from shop_goods where goods_stat = {$type_sel} and title like ? and id >= {$desc} limit {$limit_start},{$psize}";
						$arr = array($search,$search.'%','%'.$search.'%');
					}else{
						$sql = "select {$fields} from shop_goods where goods_stat = {$type_sel} limit {$limit_start},{$psize}";
						$arr = array();
					}
				}else{                            //全部
					if($search){
						$desc = GetDescId($pdo,'shop_goods',50000); 	//获取倒数第n个id值
						$sql = "select {$fields} from shop_goods where title =? and goods_stat != 6 limit 1000 union select {$fields} from shop_goods where title like ? and id >= {$desc} and goods_stat != 6 limit 1000 union select {$fields} from shop_goods where title like ? and goods_stat != 6 limit {$limit_start},{$psize}";
						$arr = array($search,'%'.$search.'%',$search.'%');
					}else{
						$sql = "select {$fields} from shop_goods where goods_stat != 6 limit {$limit_start},{$psize}";
						$arr = array();
					}
				}
			}
			$res = $pdo->dql($sql,$arr);
			if($res){
				echo json_encode($res);
			}
			break;




		//更改商户审核状态
		case 'MainStore_ChangeStat':
			$store_id = intval(I('store_id','post'));
			$store_stat = intval(I('store_stat','post'));
			$utime = time();
			if($store_id && $store_stat){
				$pdo = MyPdoCounty::init();
				if($store_stat == 2){
					$sql = "update shop_store set stat = ?,utag1=utag1+1 where id = ?";
					$res = $pdo->dml($sql,array($store_stat,$store_id));
				}else{
					$sql = "update shop_store set stat = ? where id = ?";
					$res = $pdo->dml($sql,array($store_stat,$store_id));
				}
				if($res){
					echo 'ok';
					if($store_stat == 1 || $store_stat == 3 || $store_stat == 4){
						$sql2 = 'update shop_goods set store_stat=2 where store_id = ?';
						$res2 = $pdo->dml($sql2,array($store_id));
					}else if($store_stat == 2){
						$sql2 = 'update shop_goods set store_stat=1 where store_id = ?';
						$res2 = $pdo->dml($sql2,array($store_id));

						//更新upyun的商户信息(小程序前端)
						$fields = 'id,name,addr,info,phone,wx,qq,banner,utag1,utag3';
						$sql3 = "select {$fields} from shop_store where stat =2 and id = ?";
						$res3 = $pdo->dql($sql3,array($store_id),1);
						if($res3){
							$tmp_arr = array(
								$res3['id'],
								ChangeChar($res3['name'],1),
								ChangeChar($res3['addr'],1),
								ChangeChar($res3['info'],1),
								$res3['phone'],
								$res3['wx'],
								$res3['qq'],
								$res3['banner'],
								$res3['utag1'],
								$res3['utag3']
							);
							$res4 = json_encode($tmp_arr);
							$utag1 = $res3['utag1'];
						}else{
							$res4 = '[]';
							$utag1 = 'none';
						}
						//向upyun更新商户详情数据及utag1信息版本号
						$upyun_path_update = '/detail_store/ds_'.$_SESSION['CountyInfo'][0].'_'.$store_id.'.html';
						UpyunAddFile($config,$upyun_path_update,$res4);
						$upyun_path_update_utag1 = '/detail_store/ds_'.$_SESSION['CountyInfo'][0].'_'.$store_id.'_utag1.html';
						UpyunAddFile($config,$upyun_path_update_utag1,$utag1);
					}

				}else{
					exit('err');
				}
			}
			break;




		//获取商户列表
		case 'GetStoreList':
			//dump($_SESSION,1);
			$pnow = intval(I('pnow','post'))?:1;
			$stat = intval(I('stat_type','post'))?:5;
			$search = ChangeChar(I('search','post'));
			$psize = $config['psize'];
			$limit = ($pnow-1) * $psize;
			if($stat == 5){	//全部
				if($search){
					$sql = "select * from shop_store use index(c) where name = ? limit 1000 union select * from shop_store use index(c) where name like ? limit 1000 union select * from shop_store use index(PRI) where id < 100000 and  name like ? limit {$limit},{$psize}";
					$arr = array($search,"{$search}%","%{$search}%");
				}else{
					$sql = "select * from shop_store order by id desc limit {$limit},{$psize}";
					$arr = array();
				}
			}else{ //按分类
				if($search){
					$sql = "select * from shop_store use index(d) where stat = {$stat} and name = ? limit 1000 union select * from shop_store use index(d) where stat = {$stat} and name like ? limit 1000 union select * from shop_store use index(e) where stat = {$stat} and id < 100000 and name like ? limit {$limit},{$psize}";
					$arr = array($search,"{$search}%","%{$search}%");
				}else{
					$sql = "select * from shop_store where stat = {$stat} order by id desc limit {$limit},{$psize}";
					$arr = array();
				}
			}

			$table = $config['table_prefix'].'store';
			$pdo = MyPdoCounty::init();
			//$sql = "select * from shop_store {$where} order by id desc limit {$limit},{$psize}";
			$res = $pdo->dql($sql,$arr);
			if($res){
				exit(json_encode($res));
				//Merge_Or_Make_Cache($res);
			}else{
				exit('err');
			}
			break;




		//管理成员的删除
		case 'DelUser':
			CheckAdminUser();  // 检测操作员是否为admin账户
			$id = intval(I('id','post'));
			$pdo = MyPdoCounty::init();
			$sql = "delete from shop_admin_user where id = ?";
			$res = $pdo->dml($sql,array($id));
			if($res){
				exit('ok');
			}else{
				exit('err');
			}
			break;


		//管理员列表的获取
		case 'GetAdminUserList':
			CheckAdminUser();  // 检测操作员是否为admin账户
			$pdo = MyPdoCounty::init();
			$sql = 'select * from shop_admin_user order by id desc';
			$res = $pdo->dql($sql,array());
			if($res){
				exit(json_encode($res));
			}else{
				exit('err');
			}
			break;


		//管理成员的添加
		case 'AdminUserAdd':
			CheckAdminUser();  // 检测操作员是否为admin账户
			$name = ChangeChar(I('name','post'));
			$pwd = md5(ChangeChar(I('pwd','post')));
			$info = ChangeChar(I('info','post'));
			if(!$name || !$pwd){
				exit('err1');
			}
			$pdo = MyPdoCounty::init();
			$sql = "insert ignore into shop_admin_user(name,pwd,remarks,ctime) values(?,?,?,?)";
			$res = $pdo->dml($sql,array($name,$pwd,$info,time()));
			if($res){
				exit('ok');
			}else{
				exit('err1');	//用户已存在或添加失败!
			}

			break;




		//全局服的商品分类的刷新
		case 'ShareGoodsTypeFlush':
			S('../Cache/GoodType/GoodsType_Stat',1);
			exit('ok');
			break;


		//全局服获取商品分类(先upyun缓存，后数据库)
		case 'GetShareGoodsType':
			$pdo = MyPdoShare::init();
			$sql = 'select * from share_goods_type order by orders';
			$res = $pdo->dql($sql,array());
			if($res){
				$res2 = json_encode($res);
			}else{
				$res2 = '[]';
			}
			$path = '../Cache/GoodType/GoodsType_Stat';
			if(file_exists($path)){
				$res3 = 'Gets('.$res2.')';
				UpyunAddFile($config,'GoodsType/goods_type_list.html',$res3);
				unlink($path);
			}
			exit($res2);
			break;


		//全局服的商品分类的删除
		case 'ShareGoodsTypeDel':
			CheckAdminUser();   // 检测操作员是否为admin账户
			$id = intval(I('id','post'));
			if(!$id){
				exit('err1');
			}
			$pdo = MyPdoShare::init();
			$sql = 'delete from share_goods_type where id = ? || parent_id = ?';
			$res = $pdo->dml($sql,array($id,$id));
			if($res){
				UpdateStatusSetForGoodstype($config);
				exit('ok');
			}else{
				exit('err');
			}
			break;




		//全局服的商品分类的添加
		case 'ShareGoodsTypeAdd':
			CheckAdminUser();   // 检测操作员是否为admin账户
			$name = ChangeChar(I('name','post'));
			$order = ChangeChar(I('order','post'));
			$parent_id = intval(I('parent_id','post'));
			$level = ChangeChar(I('level','post'));
			if(!$name || !$order || !$level){
				exit('err3');
			}
			$pdo = MyPdoShare::init();
			$sql = "select id from share_goods_type where level = ? and parent_id = ? and name = ?";
			$res = $pdo->dql($sql,array($level,$parent_id,$name));
			if(!$res){
				$sql2 = "insert into share_goods_type(name,parent_id,level,orders) values(?,?,?,?)";
				$res2 = $pdo->dml($sql2,array($name,$parent_id,$level,$order));
				if($res2){
					//S('../Cache/GoodType/GoodsType_Stat',1);
					UpdateStatusSetForGoodstype($config);
					exit('ok');
				}else{
					exit('err2');	//添加失败
				}
			}else{
				exit('err1'); 	//分类已存在
			}
			break;

		//全局商品分类序号的修改
		case 'GoodsTypeChangeOrder':
			$id = I('id','post');
			$order = I('order','post');
			if(!$id || !$order){
				exit('err');
			}
			$pdo = MyPdoShare::init();
			$sql = "update share_goods_type set orders = ? where id =?";
			$res = $pdo->dml($sql,array($order,$id));
			if($res){
				UpdateStatusSetForGoodstype($config);
				exit('ok');
			}
			break;



		//解密ip
		case 'DecryptIp':
			$ip = I('ip','post');
			if(!$ip){
				exit('err');
			}
			exit(IpDecrypt($ip));
			break;




		//Admin切换城市地区
		case 'CityChange':
			$County = I('County','post');
			if(!$County){
				exit('err');
			}
			$CountyInfo = explode(',',$County);
			if(count($CountyInfo)>2){
				$_SESSION['CountyInfo'] = $CountyInfo;	//缓存县信息
				echo 'ok';
			}else{
				exit('err2');
			}
			break;











		//更新城市对应的库信息
		case 'UpdateShareCityInfo':

			$name = I('name','post');
			$host = I('host','post');
		 	$code = I('code','post');
			$county_code = I('county_code','post');

			if(!$code){
				exit('err3');
			}
			if(!CheckCode($code)){
				//exit('err1'); //验证码不正确!
			}
			if(!$county_code){
				exit('err4');
			}
			CheckAdminUser();	// 检测操作员是否为admin账户

			if($host){
				$host = IpEncrypt($host);	//加密ip
			}
			
			$pdo = MyPdoShare::init(1);
			$sql = "update share_city set db_host=?,db_name=? where code = ?";
			$res = $pdo->dml($sql,array($host,$name,$county_code));
			if($res){
				echo 'ok';
				//S('../Cache/CityInfo/update_stat',1);



				$sql2 = 'select id,code,name,parent_id,level,db_host,db_name from share_city';
				$res2 = $pdo->dql($sql2,array());
				if($res2){
					$province = $province2 = $city = $city2 = $county2 = array();
					foreach($res2 as $v){
						if($v['level'] == 0){
							$province[] = $v;
						}
						if($v['level'] == 1){
							$city[] = $v;
						}
						if($v['level'] == 2){
							if($v['db_host'] != '' && $v['db_name'] != ''){
								$county2[] = $v;
							}
						}
					}
					if(count($county2) < 1){
						$FullCityStr = '{}';
						$FullCityStr2 = 'Gets('.$FullCityStr.')';
					}else{
						$city_ids = array();
						foreach($county2 as $v){
							if(!in_array($v['parent_id'],$city_ids)){
								$city_ids[] = $v['parent_id'];
	 						}
						}
						

						foreach($city_ids as $city_id){
							foreach($city as $v_city){
								if($v_city['id'] == $city_id){
									$city2[] = $v_city;
								}
							}
						}
						

						$province_ids = array();
						foreach($city2 as $v){
							if(!in_array($v['parent_id'],$province_ids)){
								$province_ids[] = $v['parent_id'];
	 						}
						}


						foreach($province_ids as $province_id){
							foreach($province as $v_province){
								if($v_province['id'] == $province_id){
									$province2[] = $v_province;
								}
							}
						}

						$county3 = json_encode($county2);
						$city3 = json_encode($city2);
						$province3 = json_encode($province2);
						$FullCityStr = '{"province":'.$province3.',"city":'.$city3.',"county":'.$county3.'}';
						$FullCityStr2 = 'Gets('.$FullCityStr.')';
					}



					$path = '/CityInfo/city_open.html';

					require_once('../Class/UpYun/vendor/autoload.php');
					$serviceConfig = new \Upyun\Config($config['upyun_bucketname'],$config['upyun_username'],$config['upyun_password']);
					$up = new \Upyun\Upyun($serviceConfig);

					//UpyunAddFile($config,$path,$FullCityStr2);
					$res_a = $up->write($path,$FullCityStr2);	//缓存已开通城市数据到upyun

					
					//StatusSet($up,'city_open');	//修改后更新状态集合文件
					$save_stat_path = '../Cache/CityInfo/update_stat';
					$status_name = 'city_open';
					DomainUpdateStat($config,$save_stat_path,$status_name,$up);
				}

			}else{
				echo 'err2'; //修改失败
			}
			break;




		//获取城市全信息数据
		case 'GetCityFullInfo':
			$pdo = MyPdoShare::init();

			if(I('open_type','post')){
				$sql = "select id,code,name,parent_id,level,db_host,db_name from share_city where level=2 and db_host != '' and db_name != ''";
			}else{
				$sql = "select id,code,name,parent_id,level,db_host,db_name from share_city";
			}
			$res = $pdo->dql($sql,array());
			if($res){
				$res2 = json_encode($res);
				$res3 = 'Gets('.$res2.')';
				$path = '../Cache/CityInfo/update_stat';
				if(I('open_type','post') && file_exists($path)){
					UpyunAddFile($config,'CityInfo/CityOpen.html',$res3);
					unlink($path);
				}
				exit($res3);
			}else{
				$res3 = 'Gets([])';
				$path = '../Cache/CityInfo/update_stat';
				if(I('open_type','post') && file_exists($path)){
					UpyunAddFile($config,'CityInfo/CityOpen.html',$res3);
					unlink($path);
				}
				exit('err');
			}
			break;





		//管理退出
		case 'AdminExit':
			unset($_SESSION['CountyInfo']);	//缓存县信息
			setCookie('admin_name','admin',time()-1);      //缓存管理员名字 
			setCookie('county_name',$CountyInfo[0],time()-1);  //缓存县名 
			echo 'ok';
			break;





		//管理登陆
		case 'AdminLogin':
			$User = I('User','post');
			$Pwd = I('Pwd','post');
			$Code = I('Code','post');
			$County = I('County','post');
			if(!$User || !$Pwd || !$Code || !$County){
				//exit('err1');	//缺少信息！
			}
			
			if(!CheckCode($Code)){
				//exit('err2');	//验证码不正确!
			}


			$CountyInfo = explode(',',$County);
			$_SESSION['admin_user'] = $User;
			$_SESSION['CountyInfo'] = $CountyInfo;	//缓存县信息
			//dump($_SESSION['CountyInfo'],1);
			//setCookie('admin_name',$User);      //缓存管理员名字
			exit('ok');


			if($User == 'admin' && $Pwd == '1'){
			}else{
				exit('err3');	//用户名或密码不正确！
			}

			break;


		//清除指定商户在数据库中的信息(县库和全局)
		case 'ClearDataBaseToStoreInfo':
			$openid = I('openid','post');
			if(!$openid){
				exit;
			}
			$pdo = MyPdoCounty::init();
			$sql2 = 'delete from shop_store where openid = ?';
			$res2 = $pdo->dml($sql2,array($openid));

			$pdo2 = MyPdoShare::init(1);
			$sql3 = 'delete from share_openid_server where openid = ?';
			$res3 = $pdo2->dml($sql3,array($openid));

			$path = 'Openid/'.$openid.'.html';
			$res4 = UpyunDelFile($config,$path);

			exit('ok');
			break;



		default :
			echo 'default';
			break;

	}







	//检测验证码
	function CheckCode($code=''){
		require_once "../Class/Plugin/VCode.class.php";
		if(Code\VCode::Check_Code($code)){
			return true;
		}else{
			return false;
		}
	}

	// 检测操作员是否为admin账户
	function CheckAdminUser(){
		if($_SESSION['admin_user'] != 'admin'){
			exit('err_admin_user');
		}
	}

	//域名列表操作时，更新其全局及操作标识状态,
	function DomainUpdateStat($config,$save_stat_path,$status_name,$up=''){
		S($save_stat_path,1);
		if(!$up){
			require_once('../Class/UpYun/vendor/autoload.php');
			$serviceConfig = new \Upyun\Config($config['upyun_bucketname'],$config['upyun_username'],$config['upyun_password']);
			$up = new \Upyun\Upyun($serviceConfig);
		}
		StatusSet($up,$status_name);	//设置状态集合
	}

	function UpdateStatusSetForGoodstype($config){
		$save_stat_path = '../Cache/GoodType/GoodsType_Stat';
		$status_name = 'goods_type_list';
		DomainUpdateStat($config,$save_stat_path,$status_name);
	}